package br.com.stakeHolder.controle;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;

import org.springframework.context.annotation.Scope;
import org.springframework.web.jsf.FacesContextUtils;

import br.com.stakeHolder.bo.StakeHolderBO;
import br.com.stakeHolder.model.StakeHolder;

@ManagedBean
@Scope("session")
public class StakeHolderAction implements Serializable{
	private static final long serialVersionUID = 4631742022923482674L;

	StakeHolderBO stakeHolderBO;

	public void setStakeHolderBO(StakeHolderBO stakeHolderBO) {
		this.stakeHolderBO = stakeHolderBO;
	}

	private List<StakeHolder> stakeHolders = new ArrayList<StakeHolder>();

	public StakeHolderAction() {
		stakeHolderBO = (StakeHolderBO) FacesContextUtils.getWebApplicationContext(FacesContext.getCurrentInstance()).getBean("stakeHolderBO");
	}

	@PostConstruct
	public void listarTodos() {
		stakeHolders = stakeHolderBO.findAll();
	}
	
	public void adicionar(){
		StakeHolder sh = new StakeHolder();
		sh.setNome("asdf");
		sh.setCargo("cargo");
		
		stakeHolderBO.add(sh);
		
		listarTodos();
	}

	public List<StakeHolder> getStakeHolders() {
		return stakeHolders;
	}

	public void setStakeHolders(List<StakeHolder> stakeHolders) {
		this.stakeHolders = stakeHolders;
	}
	
	

}
